TuiConfigEventFrame = CreateFrame('Frame')
TuiConfigEventFrame.Events = {
    ADDON_LOADED = function(self)
        self:UnregisterEvent('ADDON_LOADED')
        if not TuiDB then
            TuiDB = {
                IsGarbage = false,
                IsRepair = false,
                IsQuests = false,
                IsHealth = false,
                IsBuffTime = false
            }
        end
        local TuiConfig = CreateFrame('Frame')
        TuiConfig.name = 'Tui'
        local TuiConfigTitle = TuiConfig:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
        TuiConfigTitle:SetPoint('TOPLEFT', 16, -16)
        TuiConfigTitle:SetText('Tui Version 0.0.4')

        local TuiConfigSubText = TuiConfig:CreateFontString(nil, 'ARTWORK', 'GameFontHighlightSmall')
        TuiConfigSubText:SetSize(32, 140)
        TuiConfigSubText:SetPoint('TOPLEFT', TuiConfigTitle, 'BOTTOMLEFT', 0, -8)
        TuiConfigSubText:SetPoint('RIGHT', -32, 0)
        TuiConfigSubText:SetJustifyH('LEFT')

        local title = 'Tui - 比较忙,更新可能会有点慢,但是一定会更新的!'
        title = title .. '\r\n' .. '修改:'
        title = title .. '\r\n' .. '    1.功能默认全都不开启'
        title = title .. '\r\n' .. '    2.目标血量正确关闭'
        title = title .. '\r\n' .. '    3.快速交接任务优化 (日常 低级任务 可重复任务 不会自动接了)'
        title = title .. '\r\n' .. '在做:'
        title = title .. '\r\n' .. '    1.快速交接任务 还需要优化 (开关添加到小地图或任务栏)'
        title = title .. '\r\n' .. '    2.BUFF时间 还需要优化 (现在有问题:无时间BUFF 显示可能有问题)'
        TuiConfigSubText:SetText(title)

        local TuiConfigGarbage = CreateFrame('CheckButton', nil, TuiConfig, 'InterfaceOptionsCheckButtonTemplate')
        TuiConfigGarbage:SetPoint('TOPLEFT', TuiConfigSubText, 'BOTTOMLEFT', -2, -8)
        TuiConfigGarbage:SetChecked(TuiDB.IsGarbage)
        TuiConfigGarbage.Text:SetText('自动出售垃圾')
        TuiConfigGarbage:SetScript('OnClick', function(self, clickType, isDown)
            TuiDB.IsGarbage = self:GetChecked()
        end)

        local TuiConfigRepair = CreateFrame('CheckButton', nil, TuiConfig, 'InterfaceOptionsCheckButtonTemplate')
        TuiConfigRepair:SetPoint('TOPLEFT', TuiConfigGarbage, 'BOTTOMLEFT', 0, -8)
        TuiConfigRepair:SetChecked(TuiDB.IsRepair)
        TuiConfigRepair.Text:SetText('自动修理')
        TuiConfigRepair:SetScript('OnClick', function(self, clickType, isDown)
            TuiDB.IsRepair = self:GetChecked()
        end)

        local TuiConfigQuests = CreateFrame('CheckButton', nil, TuiConfig, 'InterfaceOptionsCheckButtonTemplate')
        TuiConfigQuests:SetPoint('TOPLEFT', TuiConfigRepair, 'BOTTOMLEFT', 0, -8)
        TuiConfigQuests:SetChecked(TuiDB.IsQuests)
        TuiConfigQuests.Text:SetText('快速交接任务')
        TuiConfigQuests:SetScript('OnClick', function(self, clickType, isDown)
            TuiDB.IsQuests = self:GetChecked()
        end)

        local TuiConfigHealth = CreateFrame('CheckButton', nil, TuiConfig, 'InterfaceOptionsCheckButtonTemplate')
        TuiConfigHealth:SetPoint('TOPLEFT', TuiConfigQuests, 'BOTTOMLEFT', 0, -8)
        TuiConfigHealth:SetChecked(TuiDB.IsHealth)
        TuiConfigHealth.Text:SetText('目标血量')
        TuiConfigHealth:SetScript('OnClick', function(self, clickType, isDown)
            TuiDB.IsHealth = self:GetChecked()
            local health = _G['TargetFrameHealthBarText']
            health:SetShown(TuiDB.IsHealth)
            if TuiDB.IsHealth then
                _G['TargetFrameHealthBar'].TextString = health
            else
                _G['TargetFrameHealthBar'].TextString = nil
            end
        end)

        local TuiConfigBuffTime = CreateFrame('CheckButton', nil, TuiConfig, 'InterfaceOptionsCheckButtonTemplate')
        TuiConfigBuffTime:SetPoint('TOPLEFT', TuiConfigHealth, 'BOTTOMLEFT', 0, -8)
        TuiConfigBuffTime:SetChecked(TuiDB.IsBuffTime)
        TuiConfigBuffTime.Text:SetText('BUFF精确时间')
        TuiConfigBuffTime:SetScript('OnClick', function(self, clickType, isDown)
            TuiDB.IsBuffTime = self:GetChecked()
        end)
        InterfaceOptions_AddCategory(TuiConfig)
    end
}
